//
//  UserQrCodeView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/14.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "UserQrCodeView.h"

@interface UserQrCodeView()<UIGestureRecognizerDelegate>

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UIImageView *qrCodeImgV;

@end

@implementation UserQrCodeView

- (instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = Color_Clear;
        [self initUI];
    }
    return self;
}
#pragma mark - UI
-(void)initUI{
    
    //点击背景隐藏
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    tap.delegate = self;
    [self addGestureRecognizer:tap];
    
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.qrCodeImgV];
    
    [self.qrCodeImgV sd_setImageWithURL:[NSURL URLWithString:[UserInfomationManager shareManager].qrcode]];
    
}

#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        self.bgView.backgroundColor = RGBA(0, 0, 0, 0.7f);
    }
    return _bgView;
}
- (UIImageView *)qrCodeImgV{
    if (!_qrCodeImgV) {
        _qrCodeImgV = [[UIImageView alloc] initWithFrame:CGRectMake(50, ScreenHeight/2-(ScreenWidth-100)/2, (ScreenWidth-100), (ScreenWidth-100))];
    }
    return _qrCodeImgV;
}

#pragma mark - SEL
- (void)show {
//    self.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [UIView animateWithDuration:0.25f animations:^{
        self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    }];
}
- (void)dismiss {
    [UIView animateWithDuration:0.25f animations:^{
//        self.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if( [touch.view isDescendantOfView:self.qrCodeImgV]) {
        return NO;
    }
    return YES;
}


@end
